# encoding: utf-8
from flask import Flask
from flask import request
from flask import make_response
import json
import re
# web modules
# img modules
import cv2
import os
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
# img modules

########## img deal

def dingwei(tz):
	img = cv2.imread(tz,0)
    
	template = cv2.imread('test2.png',0)
	res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF_NORMED)	
	threshold = 0.60 				  #匹配度
	gps = []						  
	loc = np.where(res >= threshold)  # 匹配程度大于%80的坐标y,x
	for pt in zip(*loc[::-1]):		  # *号表示可选参数
	    gps.append(pt)
	return gps 

def mission():
    tz = '1.jpg'
    res = dingwei(tz)
    for x in range(len(res)):
        re = res[x]
        return (str(re[0])+','+str(re[1]))

########## img deal

def loads_jsonp(_jsonp):
      try:
          return json.loads(re.match(".*?({.*}).*",_jsonp,re.S).group(1))
      except:
          print('s')
app = Flask(__name__)

@app.route('/', methods = ['GET','POST'])

def username():
    myfile =request.files['file']
    myfile.save('./1.jpg')
    re_text=mission()
    
    resp1 = make_response(re_text)
    resp1.mimetype = 'text/plain'
    resp1.headers['Access-Control-Allow-Origin'] = '*'
    return resp1

#json.dumps({"great":'hello world',"skt":'bad'})

if __name__ == '__main__':
    #app.run(debug=True)
    app.run(host='10.131.185.130', port=8000)

